home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ms_sh21s.zip / SH210 / SRC / SH.H < prev    next >
C/C++ Source or Header  |  1992-12-14  |  31KB  |  1,031 lines

  1. /* MS-DOS SHELL - Header File
  2.  *
  3.  * MS-DOS SHELL - Copyright (c) 1990,1,2 Data Logic Limited and Charles Forsyth
  4.  *
  5.  * This code is based on (in part) the shell program written by Charles
  6.  * Forsyth and is subject to the following copyright restrictions:
  7.  *
  8.  * 1.  Redistribution and use in source and binary forms are permitted
  9.  *     provided that the above copyright notice is duplicated in the
  10.  *     source form and the copyright notice in file sh6.c is displayed
  11.  *     on entry to the program.
  12.  *
  13.  * 2.  The sources (or parts thereof) or objects generated from the sources
  14.  *     (or parts of sources) cannot be sold under any circumstances.
  15.  *
  16.  *    $Header: /usr/users/istewart/src/shell/sh2.1/RCS/sh.h,v 2.5 1992/12/14 10:54:56 istewart Exp $
  17.  *
  18.  *    $Log: sh.h,v $
  19.  *    Revision 2.5  1992/12/14  10:54:56  istewart
  20.  *    BETA 215 Fixes and 2.1 Release
  21.  *
  22.  *    Revision 2.4  1992/11/06  10:03:44  istewart
  23.  *    214 Beta test updates
  24.  *
  25.  *    Revision 2.3  1992/09/03  18:54:45  istewart
  26.  *    Beta 213 Updates
  27.  *
  28.  *    Revision 2.2  1992/07/16  14:33:34  istewart
  29.  *    Beta 212 Baseline
  30.  *
  31.  *    Revision 2.1  1992/07/14  08:58:59  istewart
  32.  *    211 Beta updates
  33.  *
  34.  *    Revision 2.0  1992/04/13  17:39:40  Ian_Stewartson
  35.  *    MS-Shell 2.0 Baseline release
  36.  *
  37.  */
  38.  
  39. #define PATCHLEVEL        4
  40. #define    LINE_MAX        1000    /* Command line length        */
  41. #define HISTORY_MAX        100    /* History array length        */
  42.                     /* Space for full file name    */
  43. #define FFNAME_MAX        (PATH_MAX + NAME_MAX + 4)
  44. #ifdef OS2
  45. #define CMD_LINE_MAX        32000    /* Max command line length    */
  46. #else
  47. #define CMD_LINE_MAX        127    /* Max command line length    */
  48. #endif
  49. #define SSAVE_IO_SIZE        4    /* Save IO array malloc inc    */
  50. #define LEN_DEVICE_NAME_HEADER    5    /* /dev/ string length        */
  51.  
  52. #define    NPUSH            8    /* limit to input nesting    */
  53.  
  54. #define    NOFILE            20    /* Number of open files        */
  55. #define    NUFILE            10    /* # of user-accessible files    */
  56. #define    FDBASE            10    /* First file usable by Shell    */
  57.  
  58. /*
  59.  * Some characters
  60.  */
  61.  
  62. #define CHAR_UNIX_DIRECTORY    '/'
  63. #define CHAR_NEW_LINE        '\n'
  64. #define CHAR_SINGLE_QUOTE    '\''
  65. #define CHAR_DOUBLE_QUOTE    '"'
  66. #define CHAR_BACKQUOTE        '`'
  67. #define CHAR_RETURN        '\r'
  68. #define CHAR_SPACE        ' '
  69. #define    CHAR_NOT        '^'
  70. #define    CHAR_TAB        '\t'
  71. #define    CHAR_XOR        '^'
  72. #define CHAR_OPEN_PARATHENSIS    '('
  73. #define CHAR_CLOSE_PARATHENSIS    ')'
  74. #define CHAR_OPEN_BRACES    '{'
  75. #define CHAR_CLOSE_BRACES    '}'
  76. #define CHAR_OPEN_BRACKETS    '['
  77. #define CHAR_CLOSE_BRACKETS    ']'
  78. #define CHAR_TILDE        '~'
  79.  
  80.  
  81. /* Here we introduce a new boolean value - MAYBE.  This is required for
  82.  * a special case of the grave function
  83.  */
  84.  
  85. #define MAYBE        (bool)(-1)
  86.  
  87.                 /* Open in create mode            */
  88. #define O_CMASK        (O_WRONLY | O_CREAT | O_TRUNC | O_TEXT)
  89.                 /* Open in create mode for a pipe    */
  90. #define O_PMASK        (O_RDWR | O_CREAT | O_TRUNC | O_TEXT)
  91.                 /* Open in create mode for swap file    */
  92. #define O_SMASK        (O_RDWR | O_CREAT | O_TRUNC | O_BINARY)
  93. #define O_SaMASK    (O_RDWR | O_BINARY)
  94. #define O_RMASK        (O_RDONLY | O_NOINHERIT | O_TEXT)
  95.  
  96. /*
  97.  * Path format conversion
  98.  */
  99.  
  100. #define PATH_TO_UNIX(x)    ConvertPathToFormat ((x), '\\', CHAR_UNIX_DIRECTORY)
  101. #define PATH_TO_DOS(x)    ConvertPathToFormat ((x), CHAR_UNIX_DIRECTORY, '\\')
  102.  
  103. /*
  104.  * shell components
  105.  */
  106.  
  107. #define    QUOTE        0200
  108.  
  109. #define    NOBLOCK        ((C_Op *)NULL)
  110. #define    NOWORD        ((char *)NULL)
  111. #define    NOWORDS        ((char **)NULL)
  112. #define    NOPIPE        (-1)
  113.  
  114. /*
  115.  * Ignore Variables flags
  116.  */
  117.  
  118. #define DISABLE_MAILCHECK    0x0001
  119. #define DISABLE_OPTARG        0x0002
  120. #define DISABLE_OPTIND        0x0004
  121. #define DISABLE_SECONDS        0x0008
  122. #define DISABLE_RANDOM        0x0010
  123. #define DISABLE_LASTWORD    0x0020
  124. #define DISABLE_LINECOUNT    0x0040
  125.  
  126. extern int    DisabledVariables;
  127.  
  128. /*
  129.  * Result from FindLocationOfExecutable
  130.  */
  131.  
  132. #define EXTENSION_NOT_FOUND    0    /* Cannot find file        */
  133. #define EXTENSION_EXECUTABLE    1    /* OS/2 or DOS .exe or .com    */
  134. #define EXTENSION_BATCH        2    /* OS/2 or DOS .cmd or .bat    */
  135. #define EXTENSION_SHELL_SCRIPT    3    /* Shell script            */
  136.  
  137. /*
  138.  * Description of a command or an operation on commands.
  139.  * Might eventually use a union.
  140.  */
  141.  
  142. typedef struct op {
  143.     int            type;        /* operation type, see below    */
  144.     char        **words;    /* arguments to a command    */
  145.     struct ioword    **ioact;    /* IO actions (eg, < > >>)    */
  146.     struct op        *left;
  147.     struct op        *right;
  148.     char        *str;        /* identifier for case and for    */
  149. } C_Op;
  150.  
  151. #define    TCOM        1    /* command                */
  152. #define    TPAREN        2    /* (c-list)                */
  153. #define    TPIPE        3    /* a | b                */
  154. #define    TLIST        4    /* a [&;] b                */
  155. #define    TOR        5    /* ||                    */
  156. #define    TAND        6    /* &&                    */
  157. #define    TFOR        7    /* FOR                    */
  158. #define    TDO        8    /* DO                    */
  159. #define    TCASE        9    /* CASE                    */
  160. #define    TIF        10    /* IF                    */
  161. #define    TWHILE        11    /* WHILE                */
  162. #define    TUNTIL        12    /* UNTIL                */
  163. #define    TELIF        13    /* ELSE IF                */
  164. #define    TPAT        14    /* pattern in case            */
  165. #define    TBRACE        15    /* {c-list}                */
  166. #define    TASYNC        16    /* c &                    */
  167. #define    TFUNC        17    /* c () {c-list}            */
  168. #define    TSELECT        18    /* SELECT                */
  169.  
  170. /* Built in Command list */
  171.  
  172. struct    builtin {
  173.     char    *command;
  174.     int        (*fn)(int, char **);
  175.     int        mode;
  176. };
  177.  
  178. extern int    doexec (C_Op *);    /* Exec function a cheat    */
  179.  
  180. /*
  181.  * Valid values of mode
  182.  */
  183.  
  184. #define BLT_ALWAYS    0x0001    /* Always use builtin version        */
  185. #define BLT_CURRENT    0x0002    /* Currently use builtin version    */
  186. #define BLT_NOGLOB    0x0004    /* No globbing for this internal    */
  187. #define BLT_CENVIRON    0x0008    /* Don't create a new environment    */
  188. #define BLT_NOWORDS    0x0010    /* Don't split words for this internal    */
  189. #define BLT_SKIPGLOB    (BLT_CURRENT | BLT_NOGLOB)
  190. #define BLT_SKIPENVIR    (BLT_CURRENT | BLT_CENVIRON)
  191.  
  192. /*
  193.  * actions determining the environment of a process
  194.  */
  195.  
  196. #define    EXEC_WITHOUT_FORK    0x0001    /* execute without forking    */
  197. #define    EXEC_FUNCTION        0x0002    /* execute a function        */
  198. #ifdef OS2
  199. #define    EXEC_SPAWN_NOWAIT    0x0004    /* execute a non-wait        */
  200. #define EXEC_SPAWN_DETACH    0x0008    /* execute a detach        */
  201. #define EXEC_SPAWN_IGNOREWAIT    0x0010    /* Pipe processing        */
  202. #endif
  203.  
  204. /* MSDOS Memory Control Block chain structure */
  205.  
  206. #ifndef OS2
  207. #pragma pack (1)
  208. struct MCB_list    {
  209.     char        MCB_type;    /* M or Z            */
  210.     unsigned int    MCB_pid;    /* Process ID            */
  211.     unsigned int    MCB_len;    /* MCB length            */
  212. };
  213. #pragma pack ()
  214.  
  215. #define MCB_CON        'M'        /* More MCB's            */
  216. #define MCB_END        'Z'        /* Last MCB's            */
  217. #endif
  218.  
  219. /* Externs for Swapper assembler function */
  220.  
  221. #ifndef OS2
  222. extern char        cmd_line[];    /* Command line            */
  223. #endif
  224. extern char        path_line[];    /* Process path            */
  225. extern unsigned int    SW_intr;    /* interrupt pending        */
  226. extern int        LastNumberBase;    /* Last base entered        */
  227.  
  228. #ifndef OS2
  229. extern bool        SW_poll;    /* Poll keyboard        */
  230. extern unsigned int    SW_Blocks;    /* Number of blocks to read    */
  231. extern unsigned int    SW_SBlocks;    /* Short Number of blocks to    */
  232.                     /* read                */
  233. extern int        SW_fp;        /* File or EMS Handler        */
  234. extern int        SW_Pwrite;    /* Partial write to disk?    */
  235. extern unsigned long    SW_EMstart;    /* Start addr of extend mem    */
  236. extern unsigned int    SW_Mode;    /* Type of swapping to do    */
  237.                     /* 1 - disk            */
  238.                     /* 2 - Extended    memory        */
  239.                     /* 3 - EMS Driver        */
  240.                     /* 4 - XMS Driver        */
  241. extern unsigned int    SW_EMSFrame;    /* EMS Frame segment        */
  242.  
  243. extern unsigned int    etext;        /* End of text segment        */
  244. extern int        Swap_Mode;    /* Swapping mode        */
  245.  
  246. /* If you change these values, change sh7, swap_device as well */
  247.  
  248. #define SWAP_OFF    0x0000        /* No swapping            */
  249. #define SWAP_DISK    0x0001        /* Disk only            */
  250. #define SWAP_EXTEND    0x0002        /* Extended memory        */
  251. #define SWAP_EXPAND    0x0004        /* Expanded memory        */
  252. #endif
  253.  
  254. /*
  255.  * flags to control evaluation of words
  256.  */
  257.  
  258. #define    DOSUB        0x01    /* interpret $, `, and quotes        */
  259. #define    EXPAND_SPLITIFS    0x02    /* Perform blank interpretation        */
  260. #define    EXPAND_GLOBBING    0x04    /* Do globbing on name            */
  261. #define    EXPAND_MOVE    0x08    /* move words with `=' to 2nd arg. list */
  262. #define    DOTRIM        0x10    /* trim resulting string        */
  263. #define    EXPAND_CONVERT    0x20    /* Convert - and / to DOS format    */
  264.  
  265. #define    EXPAND_ALL    (DOSUB | EXPAND_SPLITIFS | EXPAND_GLOBBING |    \
  266.              EXPAND_MOVE | DOTRIM)
  267.  
  268. extern char        **ParameterArray;/* $<numeric> values        */
  269. extern int        ParameterCount;    /* $<numeric> count        */
  270. extern int        ExitStatus;
  271. extern bool        ExpansionErrorDetected;
  272. extern bool        InteractiveFlag;/* interactive            */
  273. extern bool        ProcessingEXECCommand;
  274. extern int        AllowMultipleLines;    /* Allow continuation    */
  275. extern int        *FailReturnPoint;
  276. extern int        *ErrorReturnPoint;
  277. extern bool        InParser;    /* In parser flag        */
  278. extern int        Current_Event;    /* Current history event    */
  279. extern bool        ChangeInitLoad;    /* Change load .ini point.    */
  280.  
  281. /*
  282.  * Break/Continue (in for and while), Return and Exit handler
  283.  */
  284.  
  285. typedef struct brkcon {
  286.     jmp_buf        CurrentReturnPoint;
  287.     struct brkcon    *NextExitLevel;
  288. } Break_C;
  289.                 /* Values returned by longjmp        */
  290. #define BC_LOAD        0    /* Load condition            */
  291. #define BC_BREAK    1    /* Break condition            */
  292. #define BC_CONTINUE    2    /* Continue condition            */
  293.  
  294. extern Break_C    *Break_List;    /* Break list for FOR/WHILE        */
  295. extern Break_C    *Return_List;    /* Return list for RETURN        */
  296. extern Break_C    *SShell_List;    /* SubShell list for EXIT        */
  297. extern bool    RestrictedShellFlag;    /* Read only shell        */
  298. extern bool    HistoryEnabled;
  299.  
  300. /*
  301.  * Word List structure
  302.  */
  303.  
  304. typedef struct wdblock {
  305.     short    w_bsize;
  306.     short    w_nword;
  307.     char    *w_words[1];
  308. } Word_B;
  309.  
  310. extern Word_B    *WordListBlock;
  311. extern Word_B    *IOActionBlock;
  312.  
  313. /*
  314.  * Save Standard Input/Output/Error structure
  315.  */
  316.  
  317. typedef struct save_io {
  318.     int        depth;            /* Execute recursive depth    */
  319.     int        fp[STDERR_FILENO + 1];    /* File handlers        */
  320. } Save_IO;
  321.  
  322. extern Save_IO    *SSave_IO;        /* Save IO array        */
  323. extern int    NSave_IO_E;        /* Number of entries        */
  324. extern int    MSave_IO_E;        /* Max Number of entries    */
  325.  
  326. /*
  327.  * Function tree processing
  328.  */
  329.  
  330. typedef struct FunctionList {
  331.     C_Op        *tree;        /* The tree itself        */
  332.     bool        Traced;        /* Traced flag            */
  333. } FunctionList;
  334.  
  335. extern void        *FunctionTree;    /* Function Tree root        */
  336. extern FunctionList    *CurrentFunction;
  337.  
  338. /*
  339.  * Alias processing
  340.  */
  341.  
  342. typedef struct AliasList {
  343.     char        *name;        /* The alias name        */
  344.     char        *value;        /* The alias            */
  345.     bool        Tracked;    /* Tracked Alias        */
  346. } AliasList;
  347.  
  348. extern void        *AliasTree;    /* Alias Tree root        */
  349.  
  350. /*
  351.  * Job Processing
  352.  */
  353.  
  354. #ifdef OS2
  355. typedef struct JobList {
  356.     int            Number;        /* Current number        */
  357.     PID            pid;        /* Process ID             */
  358.     char        *Command;    /* Program            */
  359. } JobList;
  360.  
  361. extern void        *JobTree;    /* Job Tree root        */
  362. extern bool        ExitWithJobsActive;    /* Exit flag        */
  363. extern int        CurrentJob;        /* No current        */
  364. extern int        PreviousJob;        /* Previous Job        */
  365. #endif
  366.  
  367. /*
  368.  * redirection
  369.  */
  370.  
  371. typedef struct ioword {
  372.     short    io_unit;    /* unit affected            */
  373.     short    io_flag;    /* action (below)            */
  374.     char    *io_name;    /* file name                */
  375. } IO_Actions;
  376.  
  377. #define    IOREAD        0x0001    /* <                    */
  378. #define    IOHERE        0x0002    /* << (here file)            */
  379. #define    IOWRITE        0x0004    /* >                    */
  380. #define    IOCAT        0x0008    /* >>                    */
  381. #define    IOXHERE        0x0010    /* ${}, ` in <<                */
  382. #define    IODUP        0x0020    /* >&digit                */
  383. #define    IOCLOSE        0x0040    /* >&-                    */
  384. #define    IOTHERE        0x0080    /* <<- (here file            */
  385. #define    IOCLOBBER    0x0100    /* >| overwrite noclobber        */
  386.  
  387. #define    IODEFAULT    (-1)    /* token for default IO unit        */
  388.  
  389. /*
  390.  * parsing & execution environment
  391.  */
  392.  
  393. typedef struct env {
  394.     char    *cline;            /* Current line buffer        */
  395.     char    *linep;            /* Current pointer in line    */
  396.     char    *eline;            /* End of line pointer        */
  397.     struct io    *iobase;
  398.     struct io    *iop;
  399.     int        *ErrorReturnPoint;
  400.     bool    eof_p;            /* EOF processing enabled    */
  401.     int        FirstAvailableFileHandler;
  402.     Word_B    *GlobbingFileList;
  403.     struct env    *oenv;            /* Previous environment        */
  404. } ShellFileEnvironment;
  405.  
  406. extern ShellFileEnvironment        e;
  407.  
  408. /*
  409.  * flags:
  410.  *
  411.  * -a: Set all environment variables to exported
  412.  * -e: Quit on error
  413.  * -f: Disable file name expansion
  414.  * -k: Look for name=value everywhere on command line
  415.  * -n: No execution
  416.  * -t: exit after reading and executing one command
  417.  * -u: Abort if environment variable is not set
  418.  * -v: Echo as read
  419.  * -x: Trace
  420.  */
  421.  
  422. #define FL_TEST(x)    (flags & (1L << ((x) - 'a')))
  423. #define FL_SET(x)    flags |= (1L << ((x) - 'a'))
  424. #define FL_CLEAR(x)    flags &= (~(1L << ((x) - 'a')))
  425.  
  426. extern long    flags;
  427.  
  428. /*
  429.  * Global flags set by set -o which do not have single letter equivalents
  430.  */
  431.  
  432. extern unsigned char    GlobalFlags;
  433.  
  434. #define FLAGS_NONE        0x00
  435. #define FLAGS_IGNOREEOF        0x01    /* Ignore EOF            */
  436. #define FLAGS_MARKDIRECTORY    0x02    /* Mark directories with /    */
  437. #define FLAGS_NOCLOBER        0x04    /* No delete on existing files    */
  438. #define FLAGS_FUNCTION        0x08    /* Special value used in    */
  439.                     /* CreateGlobalVariableList.    */
  440.                     /* Indicates a function caused  */
  441.                     /* CGVL to be called. Not used    */
  442.                     /* otherwise            */
  443. #define FLAGS_REALPIPES        0x10    /* Use Real pipes under OS/2    */
  444.  
  445. extern char    null[];        /* null value for variable        */
  446. extern int    InterruptTrapPending;    /* trap pending            */
  447. extern int    Execute_stack_depth;    /* execute function recursion    */
  448.                     /* depth            */
  449.  
  450. /*
  451.  * Mode values for new GeneralPatternMatch
  452.  */
  453.  
  454. #define GM_ALL        0        /* Match full string        */
  455. #define GM_SHORTEST    1        /* Shortest prefix/suffix    */
  456. #define GM_LONGEST    2        /* Longest prefix/suffix    */
  457.  
  458. /*
  459.  * Variable list
  460.  */
  461.  
  462. typedef struct var {
  463.     char        *name;        /* Name                */
  464.     char        *value;        /* Value            */
  465.     unsigned long    nvalue;        /* Numeric value        */
  466.     unsigned int    base;        /* Numeric base            */
  467.     unsigned int    width;        /* Field width            */
  468.     unsigned int    status;        /* Type, see below        */
  469. } VariableList;
  470.  
  471. #define    STATUS_READONLY        0x0001    /* variable is read-only    */
  472. #define    STATUS_EXPORT        0x0002    /* variable is to be exported    */
  473. #define STATUS_CANNOT_UNSET    0x0008    /* PATH Value - no unset    */
  474. #define STATUS_CONVERT_MSDOS    0x0010    /* Convert to MSDOS format    */
  475. #define STATUS_LEFT_JUSTIFY    0x0020    /* Left Justify            */
  476. #define STATUS_RIGHT_JUSTIFY    0x0040    /* Right Justify        */
  477. #define STATUS_ZERO_FILL    0x0080    /* Zero fill            */
  478. #define STATUS_LOWER_CASE    0x0100    /* Convert to lower case    */
  479. #define STATUS_UPPER_CASE    0x0200    /* Convert to upper case    */
  480. #define STATUS_INTEGER        0x0400    /* Contains integer value    */
  481. #define STATUS_TAGGED        0x0800    /* User tagged            */
  482. #define STATUS_LOCAL        0x1000    /* Local variable in function    */
  483. #define STATUS_NOEXISTANT    0x8000    /* Does not exist        */
  484.  
  485. extern void        *VariableTree;        /* Variable dictionary    */
  486. extern VariableList    *CurrentDirectory;    /* Current directory    */
  487. extern char    PS1[];            /* Prompt 1            */
  488. extern char    PS2[];            /* Prompt 2            */
  489. extern char    PS3[];            /* Prompt 3            */
  490. extern char    PS4[];            /* Prompt 4            */
  491. extern char    IFS[];            /* Interfield separators    */
  492. extern char    *LastUserPrompt;    /* Last prompt output        */
  493. extern char    *LastUserPrompt1;    /* Alternate prompt output    */
  494. extern char    PathLiteral[];        /* PATH Variable        */
  495. extern char    HomeVariableName[];    /* Home Variable        */
  496. extern char    ShellVariableName[];    /* Shell Variable        */
  497. extern char    *ParameterCountVariable;/* Parameter Count Variable (#)    */
  498. extern char    *ShellOptionsVariable;    /* Shell Options Variable (-)    */
  499. extern char    *StatusVariable;    /* Status variable (?)        */
  500. extern char    *ComspecVariable;    /* COMSPEC string        */
  501. extern char    *spcl2;
  502. extern char    SecondsVariable[];    /* Seconds string        */
  503. extern char    RandomVariable[];    /* Random string        */
  504. extern char    LineCountVariable[];    /* LINENO string        */
  505. extern char    *OldPWDVariable;    /* OLDPWD string        */
  506. extern char    *PWDVariable;        /* PWD string            */
  507. extern char    *ENVVariable;        /* ENV string            */
  508. extern char    BATExtension[];        /* .bat string            */
  509. extern char    SHELLExtension[];    /* .sh string            */
  510. extern char    EXEExtension[];        /* .exe string            */
  511. extern char    COMExtension[];        /* .com string            */
  512. extern char    HistoryFileVariable[];    /* HISTFILE string        */
  513. extern char    HistorySizeVariable[];    /* HISTSIZE string        */
  514. extern bool    FirstReadFromUser;    /* First Time I/O from user    */
  515. extern bool    UseConsoleBuffer;    /* Flag from dofc to        */
  516.                     /* GetConsoleInput        */
  517. extern char    *NotFound;        /* Not found message        */
  518. extern char    *BasicErrorMessage;    /* Basic error message        */
  519. extern char    *DirectorySeparator;    /* Directory separator        */
  520. extern char    *DeviceNameHeader;    /* /dev/            */
  521. extern char    LastWordVariable[];    /* Last word of command variable*/
  522. extern char    OptArgVariable[];    /* OPTARG            */
  523. extern char    OptIndVariable[];    /* OPTIND            */
  524. extern char    MailCheckVariable[];    /* MAILCHECK            */
  525. extern char    *Trap_DEBUG;        /* DEBUG trap variable        */
  526. extern char    *Trap_ERR;        /* ERR trap variable        */
  527. extern char    ConsoleLineBuffer[];    /* Console line buffer        */
  528. extern char    LIT_export[];        /* export literal        */
  529. extern char    LIT_history[];        /* history literal        */
  530. extern char    LIT_REPLY[];        /* Reply literal        */
  531. extern char    LIT_exit[];        /* Exit literal            */
  532. extern char    LIT_exec[];        /* Exec literal            */
  533. extern char    LIT_LINES[];        /* LINES literal        */
  534. extern char    LIT_COLUMNS[];        /* COLUMNS literal        */
  535. extern char    *LIT_2Strings;        /* 2 String concat        */
  536. extern char    *LIT_3Strings;        /* 3 string concat        */
  537. extern char    *ListVarFormat;        /* List variable format        */
  538. extern char    *Outofmemory1;        /* Out of memory string        */
  539. extern char    *LIT_Emsg;        /* Error message format        */
  540.  
  541. #ifdef OS2
  542. extern void    SetWindowName (void);    /* Set the Window Name        */
  543. extern STARTDATA *SessionControlBlock;    /* Start a session info        */
  544. #endif
  545.  
  546. /*
  547.  * SubShell Save Structure
  548.  */
  549.  
  550. typedef struct subshell {
  551.     int            depth;        /* Sub_Shell Depth        */
  552.     unsigned char    GFlags;        /* Global flags            */
  553.     long        Eflags;        /* single letter flags        */
  554.     void        *OldVariableTree;    /* Header start        */
  555. } S_SubShell;
  556.  
  557. extern S_SubShell    *SubShells;    /* Save Vars array        */
  558. extern int        NSubShells;    /* Number of entries        */
  559. extern int        MSubShells;    /* Max Number of entries    */
  560.  
  561. /* io buffer */
  562.  
  563. typedef struct iobuf {
  564.     unsigned int    id;        /* buffer id            */
  565.     char        buf[512];    /* buffer            */
  566.     char        *bufp;        /* pointer into buffer        */
  567.     char        *ebufp;        /* pointer to end of buffer    */
  568. } IO_Buf;
  569.  
  570. /* possible arguments to an IO function */
  571.  
  572. typedef struct ioarg {
  573.     char        *aword;
  574.     char        **awordlist;
  575.     int            afile;        /* file descriptor        */
  576.     unsigned int    afid;        /* buffer id            */
  577.     long        afpos;        /* file position        */
  578.     int            afoff;        /* Offset in buffer        */
  579.     IO_Buf        *afbuf;        /* buffer for this file        */
  580. } IO_Args;
  581.  
  582. #define AFID_NOBUF    (~0)
  583. #define AFID_ID        0
  584.  
  585. extern IO_Args    ioargstack[NPUSH];    /* IO argument stack        */
  586.  
  587. /* an input generator's state */
  588.  
  589. typedef struct io {
  590.     int            (*iofn)(struct io *);
  591.     IO_Args        *argp;
  592.     unsigned int    LineCount;    /* Line Count            */
  593.     char        *FileName;    /* File name            */
  594.     int            PeekedChar;    /* Current returned character    */
  595.     char        PreviousChar;    /* Previous character read by    */
  596.                     /* ReadCharacterFromIOStack()    */
  597.     char        NewLineCount;        /* for `'s        */
  598.     char        NextNonNLCharacter;    /* for `'s        */
  599.     char        TaskType;    /* reason for pushed IO        */
  600.                     /* Special processing flag for    */
  601.                     /* $* and $@            */
  602.     char        StarAmpersandProcessing;
  603. } IO_State;
  604.  
  605. /*
  606.  * StarAmpersandProcessing values
  607.  */
  608.  
  609. #define DSA_NULL    0x00        /* No special processing req    */
  610. #define DSA_STAR    0x01        /* Special processing for "$*"    */
  611. #define DSA_AMP        0x02        /* Special processing for "$@"    */
  612. #define DSA_MODE    0x03        /* Mode flag            */
  613. #define DSA_END        0x04        /* Last word processing        */
  614. #define DSA_START    0x08        /* First word processed?    */
  615. #define DSA_START1    0x10        /* Subsequent word processed    */
  616. #define DSA_END1    0x20        /* End processing for word    */
  617.  
  618. extern IO_State        iostack[NPUSH];    /* IO Stack            */
  619.  
  620. /*
  621.  * Responses from IOStackPosition () and IOBasePosition ();
  622.  */
  623.  
  624. #define IOSTACK_FIRST    0x01        /* First entry            */
  625. #define IOSTACK_INSIDE    0x02        /* Inside, excluding first    */
  626. #define IOSTACK_OUTSIDE    0x04        /* Outside            */
  627.  
  628. /*
  629.  * TaskType values
  630.  */
  631.  
  632. #define    X_ANYOTHER_IO    0x00        /* none of the below        */
  633. #define    X_EXPAND_DOLLAR    0x01        /* expanding ${}        */
  634. #define    X_FROM_STDOUT    0x02        /* expanding `'s        */
  635. #define    X_FILE_IO    0x03        /* file IO            */
  636. #define    XRESET_RF    0x40        /* Reset -r option        */
  637. #define    XRESET_XF    0x80        /* Reset -x option        */
  638.  
  639. #define XGetTaskType()    (e.iop->TaskType & 0x0f)
  640.  
  641. /* In substitution */
  642.  
  643. #define    INSUB()        (XGetTaskType () == X_FROM_STDOUT ||        \
  644.              XGetTaskType () == X_EXPAND_DOLLAR)
  645.  
  646. /*
  647.  * IO control
  648.  */
  649.  
  650. extern IO_Args        temparg;    /* temporary for PUSHIO */
  651.  
  652. #define    PUSHIO(what, arg, gen, file)                    \
  653.             ((temparg.what = (arg)),            \
  654.              AddToIOStack (&temparg, (gen), (file)))
  655.  
  656. #define    RUN(what, arg, gen, loop, file, params)                \
  657.             ((temparg.what = (arg)),            \
  658.              RunGeneratorCommand (&temparg, (gen), loop,    \
  659.                           file, params))
  660.  
  661. /*
  662.  * Extract field from a line
  663.  */
  664.  
  665. typedef struct Fields {
  666.     FILE    *FP;            /* File handler            */
  667.     char    *Line;            /* Line buffer            */
  668.     int        LineLength;        /* Line Length            */
  669.     Word_B    *Fields;    /* ptr to the start of fields    */
  670. } LineFields;
  671.  
  672. extern int    ExtractFieldsFromLine (LineFields *);
  673. extern Word_B    *SplitString (char *, Word_B *);
  674.  
  675. /*
  676.  * Type of processing required by executable program.
  677.  */
  678.  
  679. struct ExecutableProcessing {
  680.     char        *Name;
  681.     unsigned int    Flags;
  682.     unsigned char    FieldSep;
  683. };
  684.  
  685. extern void    CheckProgramMode (char *, struct ExecutableProcessing *);
  686.                     /* Current executable mode    */
  687. extern struct ExecutableProcessing     ExecProcessingMode;
  688.  
  689. /* Flags set a bit to indicate program mode */
  690.  
  691. #define EP_NONE        0x000        /* Use PSP command line        */
  692. #define EP_DOSMODE    0x001        /* Use DOS mode extended line    */
  693. #define EP_UNIXMODE    0x002        /* Use UNIX mode extended line    */
  694. #define EP_NOEXPAND    0x004        /* Use -f for this command    */
  695. #define EP_ENVIRON    0x008        /* Use environ for variable    */
  696. #define EP_NOSWAP    0x010        /* Do not swap for this command    */
  697. #define EP_EXPORT    0x040        /* Use -m for this command    */
  698. #define EP_CONVERT    0x080        /* Use conversion        */
  699. #define EP_NOWORDS    0x100        /* Do word expansion        */
  700.  
  701. /*
  702.  * storage allocation
  703.  */
  704.  
  705. extern int    MemoryAreaLevel;    /* current allocation area */
  706.  
  707. /* Functions */
  708.  
  709. extern void    main (int, char **);
  710.  
  711. extern void    ShellErrorMessage (char *, ...);
  712. extern void    PrintErrorMessage (char *, ...);
  713. extern int    PrintWarningMessage (char *, ...);
  714.  
  715. extern void    ExitTheShell (bool);
  716.  
  717. extern void    TerminateCurrentEnvironment (void);
  718. extern bool    CreateNewEnvironment (int);
  719. extern void    QuitCurrentEnvironment (void);
  720.  
  721. extern void    InterruptSignalled (int);
  722. extern void    TerminateSignalled (int);
  723. extern void    RunTrapCommand (int);
  724.  
  725. extern void    SetShellSwitches (void);
  726. extern Word_B    *AddWordToBlock (char *, Word_B *);
  727. extern char    **GetWordList (Word_B *);
  728. extern char    *IntegerToString (int);
  729. extern char    *GenerateTemporaryFileName (void);
  730. extern int    (*IsCommandBuiltIn (char *, int *))();
  731. extern char    *BuildNextFullPathName (char *, char *, char *);
  732. extern int    LookUpSymbol (char *);
  733. extern int    GetNumericValue (char *);
  734. extern bool    ConvertNumericValue (char *, long *, int);
  735. extern char    *BuildFileName (char *);
  736. extern int    CreateGlobalVariableList (unsigned char);
  737. extern void    DeleteGlobalVariableList (void);
  738. extern Word_B    *AddParameter (char *, Word_B *, char *);
  739.  
  740. extern int    RestoreStandardIO (int, bool);
  741. extern void    RestoreCurrentDirectory (char *);
  742. extern void    RestoreEnvironment (int, int);
  743. extern bool    CheckForRestrictedShell (char *);
  744. extern void    OutputUserPrompt (char *);
  745. extern void    DisplayLineWithControl (char *);
  746. extern void    GetCurrentDirectory (void);
  747. extern int    OpenForExecution (char *, char **, int *);
  748. extern bool    AddToStackForExection (char *);
  749. extern char    **BuildCommandEnvironment (void);
  750. extern int    ProcessOutputMetaCharacters (char **);
  751. extern char    *ConvertPathToFormat (char *, char, char);
  752. extern int    CheckForScriptFile (char *, char **, int *);
  753. extern void    PrintVersionNumber (FILE *);
  754. #ifndef OS2
  755. extern void    ClearSwapFile (void);
  756. #endif
  757. extern void    ClearExtendedLineFile (void);
  758.  
  759. extern bool    GeneralPatternMatch (char *, char *, bool, char **, int);
  760. extern bool    SuffixPatternMatch (char *, char *, char **, int);
  761. extern bool    any (char, char *);
  762. extern bool    anys (char *, char *);
  763. extern int    _GP_SortCompare    (char **, char **);
  764. extern int    CountNumberArguments (char **);
  765.  
  766. extern long    EvaluateMathsExpression (char *);
  767. extern bool    ValidMathsExpression (char *, long *);
  768.  
  769. extern C_Op    *BuildParseTree (void);
  770. extern int    ExecuteParseTree (C_Op *, int, int, int);
  771. extern int    RunGeneratorCommand (IO_Args *, int (*)(IO_State *), bool,
  772.                      char *, char **);
  773. #ifndef OS2
  774. extern int    SA_spawn (char **);
  775. #endif
  776. extern int    ExecuteACommand (char **, int);
  777. extern int    FindLocationOfExecutable (char *, char *);
  778.  
  779. extern int    GetNextCharacter (int);
  780. extern void    ReturnGotCharacter (int);
  781. extern int    ReadCharacterFromIOStack (void);
  782. extern bool    CheckForEndOfFile (void);
  783. extern void    AddToIOStack (IO_Args *, int (*)(IO_State *), char *);
  784. extern int    CloseUpIOStack (IO_State *, bool);
  785. extern int    ReMapIOHandler (int);
  786. extern int    IOStackPosition (int);
  787. extern int    IOBasePosition (void);
  788.  
  789. extern char    **eval (char **, int, struct ExecutableProcessing *);
  790. extern char    *evalstr (char *, int);
  791. extern int    subgetc (char, bool);
  792.  
  793. extern bool    ChangeInitialisationValue (char *, int);
  794. extern void    Configure_Keys (void);
  795.  
  796. /*
  797.  * Keyboard Input
  798.  */
  799.  
  800. #ifndef OS2
  801. extern int    Read_Keyboard (void);
  802. #endif
  803. extern void    PositionCursorInColumnZero (void);
  804. extern int    GetConsoleInput (IO_Args *);
  805. extern bool    Interactive (void);
  806. extern int    CollectInputToCharacter (int, int);
  807. extern bool    IsConsole (int);
  808. extern bool    IsDirectory (char *);
  809. extern int    GetEOFKey (void);
  810.  
  811. #ifndef NO_HISTORY
  812. extern void    GetLineFromConsole (void);
  813. #endif
  814.  
  815. /*
  816.  * Valid values to ScanForEndofWord
  817.  */
  818.  
  819. #define SWT_STDOUT    0        /* $(...)            */
  820. #define SWT_EVARIABLE    1        /* ${...}            */
  821. #define SWT_LET        2        /* ((....))            */
  822. #define SWT_CONDITIONAL    3        /* [[....]]            */
  823. #define SWT_EXPRESSION    4        /* $((....))            */
  824.  
  825. extern int    ScanForEndofWord (int, int);
  826.  
  827. /*
  828.  * Variable Name functions
  829.  */
  830.  
  831. extern void        UnSetVariable (char *, bool);
  832. extern void        SetVariableStatus (char *, int);
  833. extern void        ClearVariableStatus (char *, int);
  834. extern char        *GetVariableAsString (char *, bool);
  835. extern long        GetVariableAsNumeric (char *);
  836. extern void        SetVariableFromString (char *, char *);
  837. extern void        SetVariableFromNumeric (char *, long);
  838. extern void        HandleSECONDandRANDOM (void);
  839. extern bool        AssignVariableFromString (char *);
  840. extern char        IsValidVariableName (char *);
  841. extern bool        IsVariableAssignment (char *);
  842. extern VariableList    *LookUpVariable (char *, bool);
  843. extern int        FindVariable (void *, void *);
  844.  
  845. /*
  846.  * Underlying Get Next Character functions
  847.  */
  848.  
  849. extern int        Line_GetNextCharacter (IO_State *);
  850. extern int        WordList_GetNextCharacter (IO_State *);
  851. extern int        SpacedWordList_GetNextCharacter (IO_State *);
  852. extern int        String_GetNextCharacter (IO_State *);
  853. extern int        QuotedString_GetNextCharacter (IO_State *);
  854. extern int        File_GetNextCharacter (IO_State *);
  855. extern int        NonNLStdOut_GetNextCharacter (IO_State *);
  856. extern int        StdOut_GetNextCharacter (IO_State *);
  857. extern int        NonQuoteSO_GetNextCharacter (IO_State *);
  858. extern int        FileLine_GetNextCharacter (IO_State *);
  859.  
  860. /*
  861.  * Memory management
  862.  */
  863.  
  864. extern char        *AllocateMemoryCell (size_t);
  865. extern void        ReleaseMemoryCell (void *);
  866. extern void        ReleaseMemoryArea (int);
  867. extern void        SetMemoryAreaNumber (void *, int);
  868. extern int        GetMemoryAreaNumber (void *);
  869. extern char        *GetAllocatedSpace (size_t);
  870. extern char        *StringSave (char *);
  871. extern char        *StringCopy (char *);
  872. #ifdef DEBUG_MEMORY
  873. extern void        DumpMemoryCells (int);
  874. #define exit(x)        DumpMemoryCells (x)
  875. #endif
  876.  
  877. /*
  878.  * Here file processing
  879.  */
  880.  
  881. extern void        SaveHereFileInfo (char *, IO_Actions *);
  882. extern void        GetAllHereFiles (void);
  883. extern int        OpenHereFile (char *, int);
  884. extern void        ScrapHereList (void);
  885. extern void        FreeAllHereFiles (int);
  886.  
  887. /*
  888.  * UNIX File I/O function emulation
  889.  */
  890.  
  891. extern int        S_open (bool, char *, int, ...);
  892. extern int        S_close (int, bool);
  893. extern int        S_dup (int);
  894. extern int        S_dup2 (int, int);
  895. extern int        S_Remap (int, int);
  896. extern void        S_Delete (int);
  897. extern int        OpenAPipe (void);
  898. extern void        CloseThePipe (int);
  899. extern void        CloseAllHandlers (void);
  900. extern unsigned int    GetCurrentDrive (void);
  901. extern unsigned int    SetCurrentDrive (unsigned int);
  902. extern bool        SetUpIOHandlers (IO_Actions *, int, int);
  903. extern int        GetRootDiskDrive (void);
  904. extern char        *CheckDOSFileName (char *);
  905.  
  906. /*
  907.  * Shell Functions
  908.  */
  909.  
  910. extern FunctionList    *LookUpFunction (char *);
  911. extern bool        SaveFunction (C_Op *);
  912. extern void        DeleteFunction (C_Op *);
  913. extern void        PrintFunction (C_Op *);
  914. extern C_Op        *CopyFunction (C_Op *);
  915. extern int        PrintAllFunctions (void);
  916.  
  917. /*
  918.  * Alias processing
  919.  */
  920.  
  921. extern AliasList    *LookUpAlias (char *, bool);
  922. extern void        DeleteAlias (char *);
  923. extern bool        SaveAlias (char *, char *, bool);
  924. extern void        PrintAlias (char *);
  925. extern bool        IsValidAliasName (char *, bool);
  926. extern void        UnTrackAllAliases (void);
  927. extern int        PrintAllAlias (bool);
  928.  
  929. /*
  930.  * Job Processing
  931.  */
  932.  
  933. #ifdef OS2
  934. extern int        AddNewJob (PID pid, char *command);
  935. extern void        DeleteJob (PID);
  936. extern int        PrintJobs (bool);
  937. extern int        NumberOfActiveJobs (void);
  938. extern JobList        *LookUpJob (int);
  939. extern JobList        *SearchForJob (char *);
  940. extern int        PrintProcessTree (pid_t);
  941. #endif
  942.  
  943. /*
  944.  * History Processing
  945.  */
  946.  
  947. extern void        AddHistory (bool);
  948. extern void        LoadHistory (void);
  949. extern void        DumpHistory (void);
  950. extern void        ClearHistory (void);
  951. extern void        PrintHistory (bool, bool, int, int, FILE *);
  952. extern int        GetLastHistoryEvent (void);
  953. extern int        SearchHistory (char *);
  954. extern void        FlushHistoryBuffer (void);
  955. extern void        DeleteLastHistory (void);
  956. extern char        *GetLastHistoryString (void);
  957.  
  958. /*
  959.  * Interrupt handling
  960.  */
  961.  
  962. #ifndef OS2
  963. extern void interrupt    SW_Int24 (void);    /* Int 24 New address    */
  964. extern void interrupt    SW_Int23 (void);    /* Int 23 New address    */
  965. extern void interrupt    SW_Int00 (void);    /* Int 00 New address    */
  966. extern bool        SW_I23_InShell;        /* In the shell        */
  967. #endif
  968.  
  969. /*
  970.  * XMS Driver functions
  971.  */
  972.  
  973. #ifndef OS2
  974. extern void (far *SW_XMS_Driver) (void);    /* XMS Driver Interface    */
  975. extern int        SW_XMS_Gversion (void);
  976. extern int        SW_XMS_Allocate (unsigned int);
  977. extern int        SW_XMS_Free (int);
  978. extern int        SW_XMS_Available (void);
  979. #endif
  980.  
  981. /*
  982.  * Modified getopt for shell
  983.  */
  984.  
  985. extern int        OptionIndex;        /* optind        */
  986. extern int        OptionStart;        /* start character    */
  987. extern char        *OptionArgument;    /* optarg        */
  988.  
  989. extern int        GetOptions (int, char **, char *, int);
  990.  
  991. /*
  992.  * Save structure for getopts command
  993.  */
  994.  
  995. typedef struct GetoptsIndex {
  996.     int        Index;
  997.     int        SubIndex;
  998. } GetoptsIndex;
  999.  
  1000. extern void        ResetGetoptsValues (bool);
  1001. extern void        GetGetoptsValues (GetoptsIndex *);
  1002. extern void        SaveGetoptsValues (int, int);
  1003.  
  1004. /*
  1005.  * General Functions
  1006.  */
  1007.  
  1008.  
  1009. /*
  1010.  * Flag values
  1011.  */
  1012.  
  1013. #define GETOPT_PLUS    0x01        /* Allow plus sign        */
  1014. #define GETOPT_MESSAGE    0x02        /* Print error message        */
  1015. #define GETOPT_PRINT    0x04        /* doecho special        */
  1016.  
  1017. /*
  1018.  * TSEARCH Functions
  1019.  */
  1020.  
  1021. typedef enum { preorder, postorder, endorder, leaf }    VISIT;
  1022.  
  1023. /*
  1024.  * Tree functions
  1025.  */
  1026.  
  1027. extern void    *tsearch (void *, void **, int (*)(const void *, const void *));
  1028. extern void    *tfind (void *, void **, int (*)(const void *, const void *));
  1029. extern void    *tdelete (void *, void **, int (*)(const void *, const void *));
  1030. extern void    twalk (const void *, void (*)(const void *, VISIT, int));
  1031.